package com.biz.primus.base.vo;

import com.biz.primus.base.vo.commodity.ProductFinalPriceVo;
import com.biz.primus.base.vo.commodity.ProductListItemVo;

import java.util.function.Function;

/**
 * @author jiangnan
 * @Description:
 */
public class ProductListItemVo2ProductListRestVo implements Function<ProductListItemVo, ProductListRestVo> {
    @Override
    public ProductListRestVo apply(ProductListItemVo input) {
        ProductListRestVo respVo = new ProductListRestVo();
        if (input.getBase() == null) {
            return null;
        }
        if (input.getProductStockVo() == null) {
            return null;
        }
        ProductFinalPriceVo priceVo = input.getProductFinalPriceVo();
        if (priceVo ==null){
            return null;
        }
        respVo.setTraceId(input.getTraceId());
        respVo.setProductId(input.getBase().getProductId());
        respVo.setProductCode(input.getBase().getProductCode());
        respVo.setName(input.getBase().getName());
        respVo.setLogo(input.getBase().getLogo());
        respVo.setPackageNumber(input.getBase().getPackageNumber());
        respVo.setSaleStatus(input.getBase().saleStatus());
        respVo.setWarehouseQuantity(input.getProductStockVo().getStockRespVo().getWarehouseQuantity());
        respVo.setQuantity(input.getProductStockVo().getStockRespVo().getQuantity());
        respVo.setPrice(priceVo.getFinalPrice());
        respVo.setFclSinglePrice(priceVo.getFclSinglePrice());
        respVo.setPredictTime(input.getPredictTime());
        if (input.getProductPromotionTagRespVo()!=null){
            respVo.setProductPromotionTag(input.getProductPromotionTagRespVo().getPromotionTags());
        }
        return respVo;
    }

}
